package perfectsquare;

import java.util.Scanner;
public class Solution {

	public Solution() {
		
	}

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);
		Solution square = new Solution();

		while(n > 0){
			n--;
			line = sc.nextLine();
			String[] vals = line.split(" ");

			square.squareNumber(Integer.parseInt(vals[0]), Integer.parseInt(vals[1]));
		}
		
		sc.close();
	}
	
	public void squareNumber(int a, int b)	{
		int count =0;
		for (long i = 0; i < b; i ++){
			
			long square = i*i;
			if(square >= a && square <=b){
				count++;				
			}
			if(square >= b){
				break;
			}
		}
		System.out.println(count);
	}
}
